package com.huobao.yunying.activitys;

import java.util.List;
import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.adapters.Adapter_MyYouhuiquanHongBao;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.entity.MyYouhuiquanHongbao;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class Act_MyHongbao extends HuobaoBaseActivity {

	private Adapter_MyYouhuiquanHongBao adapter;
	@ViewInject(R.id.listview)
	private ListView listview;
	
	@ViewInject(R.id.image)
	private ImageView image;
	@ViewInject(R.id.tv_1)
	private TextView text;
	@ViewInject(R.id.llyt)
	private LinearLayout llyt;
	@Override
	protected int getContentView() {
		// TODO Auto-generated method stub
		return R.layout.layout_hongbao_listview;
	}

	@Override
	protected String getTitleText() {
		// TODO Auto-generated method stub
		return "我的红包";
	}

	@Override
	protected void init() {
		adapter = new Adapter_MyYouhuiquanHongBao(context, true);
		listview.setAdapter(adapter);
		getData();
	}

	private void getData(){
		Map<String, String> map = HttpUtil.getParams("app","member","act","mybonus");
		Http.getInstant().sendRequest(context, map, new HttpListener() {
			
			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				List<MyYouhuiquanHongbao> list = JSON.parseArray(jsonObject.getString("retval"), MyYouhuiquanHongbao.class);
				adapter.clear();
				adapter.addAll(list);
				if(list.size() == 0){
					llyt.setVisibility(View.VISIBLE);
					listview.setVisibility(View.GONE);
					image.setImageResource(R.mipmap.hb_k);
					text.setText("您还未领取红包哦，去掌婴转转领取红包");
				}else{
					llyt.setVisibility(View.GONE);
					listview.setVisibility(View.VISIBLE);
				}
			}
			
			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub
				
			}
		});
	}

}
